package com.zytool.easyrestful.core.utils;

public class NamingUtil {

    public static String lineToHump(String columnName) {
        StringBuffer result = new StringBuffer();
        String[] splits = columnName.split("_");
        for (int i = 0; i < splits.length; i++) {
            String s = splits[i];
            if (result.length() == 0) {
                result.append(s.toLowerCase());
            } else {
                result.append(s.substring(0, 1).toUpperCase());
                result.append(s.substring(1).toLowerCase());
            }
        }
        return result.toString();
    }

    public static String humpToLine(String fieldName) {
        StringBuffer result = new StringBuffer(fieldName);
        int temp = 0;
        for (int i = 0, len = fieldName.length(); i < len; i++) {
            if (Character.isUpperCase(fieldName.charAt(i))) {
                result.insert(i + temp, "_");
                temp++;
            }
        }
        return result.toString().toUpperCase();
    }
}
